/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.admin.service;

import org.springblade.modules.admin.dto.PlanContentSaveDto;
import org.springblade.modules.admin.dto.rescue.PlanAddUserDTO;
import org.springblade.modules.admin.dto.rescue.PlanAddUserSearchDTO;
import org.springblade.modules.admin.dto.rescue.RescueListDTO;
import org.springblade.modules.admin.dto.sugar.rescue.SugarRescueSearchDTO;
import org.springblade.modules.admin.entity.MaintainMalfunctionRescue;
import org.springblade.core.mp.base.BaseService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.admin.entity.MaintainPlanContent;
import org.springblade.modules.admin.vo.*;
import org.springblade.modules.admin.vo.plan.PlanRescueDetailVO;
import org.springblade.modules.admin.vo.plan.TodayTaskListVO;
import org.springblade.modules.admin.vo.plan.wx.UserTodayPlanDetailVo;
import org.springblade.modules.admin.vo.rescue.*;
import org.springblade.modules.admin.vo.rescue.map.MapRescueBuildingDetailVO;
import org.springblade.modules.admin.vo.rescue.map.MapRescueBuildingListVO;
import org.springblade.modules.admin.vo.rescue.map.MapRescuePlanDetailVO;
import org.springblade.modules.admin.vo.rescue.map.MapUserInfoCardDetailPlanListVO;
import org.springblade.modules.admin.vo.sugar.rescue.*;
import org.springblade.modules.admin.vo.sugar.StatisticsTrendVO;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 救援工单明细 服务类
 *
 * @author ysq
 * @since 2023-02-25
 */
public interface IMaintainMalfunctionRescueService extends BaseService<MaintainMalfunctionRescue> {

	/**
	 * 救援工单分页
	 *
	 * @param rescueListDTO 查询条件
	 * @return 数据集
	 */
	IPage<RescueListVo> selectMaintainMalfunctionRescuePage(IPage<RescueListVo> page, RescueListDTO rescueListDTO);


	/**
	 * 获取救援任务的统计信息
	 *
	 * @return 数据集
	 */
	PlanStatisticVo getPlanStatistic();


	/**
	 * 获取救援工单详情
	 *
	 * @param planId 救援工单id
	 * @return 数据集
	 */
	RescuePlanDetail detail(Long planId);


	/**
	 * 获取指派人员列表
	 * @param elevatorIds 电梯id
	 * @param type 1:电梯责任人2:负责组，3：上次维保人员,4:分配人员
	 * @param planId
	 * @param userName
	 * @return 数据集
	 */
    List<UserInfoVo> getUserList(List<Long> elevatorIds, Integer type, Long planId, String userName);

	/**
	 * 救援任务撤销操作
	 * @param planId 工单id
	 * @param type 操作来源：0-系统操作，1-梯联网操作
	 * @return 数据集
	 */
	Boolean rescueCancel(Long planId, Integer type);

	/**
	 * 分配工单
	 * @param planAddUserDTO 用户id
	 * @return 数据集
	 */
	Boolean planAddUser(PlanAddUserDTO planAddUserDTO);


	/**
	 * 获取救援电梯信息--用户详情页面共用
	 * @param elevatorId 电梯id
	 * @param planId 工单id
	 * @param malfunctionRescue 救援信息如果为空,根据工单id获取
	 * @return 数据集
	 */
	RescueElevatorInfoVo getRescueElevatorInfo(Long elevatorId,Long planId,MaintainMalfunctionRescue malfunctionRescue);

	/**
	 * 分页查询已出发工单状态，且救援人仅为该员工
	 * @param rescueListDTO 查询条件
	 * @return 分页结果数据集
	 */
	IPage<RescueListVo> selectMaintainRescueOnlyHim(RescueListDTO rescueListDTO);

	/**
	 * 用户已到达状态 -> 系统代签&&修改工单状态
	 * @param userId 当前用户id
	 * @param planId 救援工单id
	 * @return 是否成功
	 */
	boolean rescueConfirm(Long userId, Long planId);

	/**
	 * 地图-救援人员信息
	 * @param userStatus 人员状态筛选: 1-保养中，2-维修中，3-救援中，4-空闲，5-今日已打卡
	 * @param planId 工单id
	 * @return
	 */
    List<MapUserInfoVO> mapUserList(List<Integer> userStatus, Long planId);

	/**
	 * 大屏地图-人员列表
	 * @param search
	 * @return
	 */
	List<MapUserInfoVO> screenMapUserList(String search,String vehicles,String isSign,String planTypes,Integer searchMin,boolean isOnlyShowRescue);

	/**
	 * 地图-救援人员卡片详情
	 * @param userIds 用户id集合
	 * @param elevatorId 电梯id
	 * @param planId 工单id
	 * @return
	 */
	List<MapUserInfoCardDetailVO> mapUserCardDetails(List<Long> userIds, Long elevatorId, Long planId);

	/**
	 * 大屏地图-人员详情
	 * @param userId
	 * @return
	 */
	MapUserInfoCardDetailVO mapUserScreenDetail(Long userId);

	/**
	 * 地图-救援人员详情
	 * @param planId
	 * @return
	 */
	List<MapUserInfoDetailVO> mapUserDetails(Long planId);

	/**
	 * 救援工单详情
	 * @param planId
	 * @return
	 */
	RescueOrderDetail rescueDetail(Long planId);

	/**
	 * 救援工单详情列表
	 * @return
	 */
	List<RescueOrderDetail> rescueDetailList();

	/**
	 * 梯联网-救援详情
	 * @param tlwJoinId
	 * @return
	 */
	TlwRescueDetailVO tlwRescueDetail(String tlwJoinId);

	/**
	 * 在保项目列表
	 * @return
	 */
	List<MaintainBuildingListVO> maintainBuildingList(String search);

	/**
	 * 筛选-在保项目列表
	 * @param buildingName
	 * @param address
	 * @param phone
	 * @param isOnlyShowRescue 是否只展示救援的项目
	 * @return
	 */
	List<EffectiveBuildingVO> effectiveBuildingList(String buildingName, String address, String phone, boolean isOnlyShowRescue);

	/**
	 * 筛选-在保电梯列表
	 * @param buildingId
	 * @param elevatorNum
	 * @return
	 */
	List<EffectiveElevatorVO> effectiveElevatorList(String buildingId, String elevatorNum, boolean isOnlyShowRescue);

    List<MapRescueBuildingListVO> mapRescueBuildingList(String search, boolean isOnlyShowRescue);

	MapRescueBuildingDetailVO mapRescueBuildingDetail(Long buildingId);
	/**
	 * 救援中项目统计
	 * @return
	 */
	Map<String, Object> rescueProjectScreen();

	List<MapUserInfoVO> mapRescueBuildingRecentlyUser(Long buildingId, List<String> vehicle, List<Integer> workStatus, Integer distance, List<Integer> isSign, Integer searchMin, Long elevatorId, List<String> skillKeys, String keyword);

	List<MapUserInfoVO> mapRescueBuildingRecentlyMaintainUser(Long buildingId, List<String> vehicle, List<Integer> workStatus, Integer distance, List<Integer> isSign, Integer searchMin, Long elevatorId, List<String> skillKeys, String keyword);

	List<MapUserInfoVO> mapRescueBuildingRecentlyBuildingUser(Long buildingId, List<String> vehicle, List<Integer> workStatus, Integer distance, List<Integer> isSign, Integer searchMin, Long elevatorId, List<String> skillKeys, String keyword);

	List<MaintainBuildingListVO> mapRescueUserRecentlyBuilding(Long userId);

	RescueOverviewVO selectRescueOverview(SugarRescueSearchDTO searchDTO);

    List<RescueAreaVO> selectRescueArea(SugarRescueSearchDTO searchDTO);

	Map<Integer,Long> selectRescueHighTime(SugarRescueSearchDTO searchDTO);

    List<StatisticsTrendVO> selectRescueCountTrend(SugarRescueSearchDTO searchDTO);

	List<Map<String,Object>> selectRescueArriveDurationRadar(SugarRescueSearchDTO searchDTO);

    Map<String,Object> selectRescueArriveDurationDetail(SugarRescueSearchDTO searchDTO);

	List<StatisticsTrendVO> selectRescueArriveDurationOvertimeTrend(SugarRescueSearchDTO searchDTO);

	Map<String,Object> selectRescueAllocateDurationTrend(SugarRescueSearchDTO searchDTO);

	Map<String,Object> selectRescueArriveDurationTrend(SugarRescueSearchDTO searchDTO);

	Map<String,Object> selectRescueWorkDurationTrend(SugarRescueSearchDTO searchDTO);

	/**
	 * 根据来源统计
	 * @param beginTime 开始时间
	 * @param endTime 结束时间
	 * @return 统计结果
	 */
	Map<String, String> countByResources(SugarRescueSearchDTO searchDTO);

    Object init();

	/**
	 * 获取工单信息（忽略租户）
	 * @param planId
	 * @return
	 */
	MaintainPlanContent getMaintainPlanById(Long planId);

    StatisticsTrendVO selectRescueTiringPro(SugarRescueSearchDTO searchDTO);

    List<Map<String,Object>> selectArriveDurationOvertimeList(SugarRescueSearchDTO searchDTO);

    Map<String,Object> selectRescueTiringProDetail(SugarRescueSearchDTO searchDTO);

	/**
	 * 梯联网-救援人员坐标
	 * @param planId
	 * @return
	 */
	MapUserInfoDetailVO tlwPlanRescueUserCoordinate(Long planId);

    Map<String,Object> mapBuildingDetailElevatorList(Long buildingId,String keyword);

	/**
	 * 救援详情列表
	 * @param buildingId
	 * @param elevatorId
	 * @return
	 */
	MapRescuePlanDetailVO planRescueDetailList(Long buildingId, Long elevatorId);

	/**
	 * 获取救援电梯设备状态
	 * @param elevatorId
	 * @return
	 */
	DeviceStatusVO getElevatorDeviceStatus(Long elevatorId);

	/**
	 * 获取救援工单详情
	 * @param planId
	 * @return
	 */
	PlanRescueDetailVO getRescueDetail(Long planId);

	Map<String,Object> getMaintainBuildingElevatorCount();

	Map<String,Object> getPlanResultCount();

    List<Long> selectRescueSugarUser(String tenantId);

    RescueRealTimeCountVO selectRealTimeCount();

    List<RescueRealTimePlanListVO> selectRealTimePlanList(Integer planStatus,Integer arrivalWarning);

    List<RescueRealTimeListVO> selectRealTimeBuildingList();

	List<RescueRealTimeListVO> selectRealTimeUserList();

    List<MapUserInfoCardDetailPlanListVO> mapUserScreenDetailPlanList(Long userId, Integer typeStatus);

	/**
	 * 工单指派人员维修列表
	 *
	 * 1：闲忙情况，技能等级，电梯品牌，附近的人搜索
	 * @param planAddUserSearchDTO 查询条件
	 * @return 数据集
	 */
	List<UserInfoVo> getUserListV2(PlanAddUserSearchDTO planAddUserSearchDTO);


	/**
	 * 获取人员当天的工单信息
	 * @param userId 用户id
	 * @return 数据集
	 */
    UserTodayPlanDetailVo userPlanInfo(Long userId);

	/**
	 * 获取今日任务列表
	 * @param userId
	 * @param typeStatus
	 * @return
	 */
	List<TodayTaskListVO> getTodayTaskList(Integer typeStatus, Long userId);

	/**
	 * 调度分页
	 * @param dispatcherPageReqVO
	 * @param page
	 * @return
	 */
	IPage<DispatcherPageRespVO> dispatcherPage(DispatcherPageReqVO dispatcherPageReqVO, IPage<DispatcherPageRespVO> page);

	/**
	 * 调度统计
	 * @param dispatcherPageReqVO
	 * @return
	 */
	DispatcherStatisticsVO dispatcherStatistics(DispatcherPageReqVO dispatcherPageReqVO);

	/**
	 * 判断是否有关联的维修单
	 * @param id
	 * @return
	 */
	Boolean hasRelaMalOrder(Long id);

	/**
	 * 上报维修
	 * @param planContentSaveDto
	 * @return
	 */
	Long reportMal(PlanContentSaveDto planContentSaveDto);

    List<Map<String, Object>> getBiRescuePlanDetailListV2();

	List<Map<String, Object>> getBiRescuePlanCountListV2();

	/**
	 * 催办
	 * @param planId
	 * @return
	 */
    Boolean reminder(Long planId);
}
